#include <stdio.h>
#include <string.h>

#define MAXLINE 1000

int getline2(char s[], int lim);
int strrindex(char s[], char t[]);

char pattern[] = "ould";

int main()
{
    char line[MAXLINE];
    int index = 0;

    while (getline2(line, MAXLINE) > 0){
        printf("line = %s", line);
        index = strrindex(line, pattern) ;
        printf("index = %d\n", index);   
    }

    return 0;
}

int getline2(char s[], int lim)
{
    int c, i;
    i = 0;
    while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
    {
        s[i++] = c;
    }
    if(c == '\n')
        s[i++] = '\n';
    s[i] = '\0';
    return i;    
}

int strrindex(char s[], char t[])
{
    int i, j, k;

    for(i = strlen(s) - 1; i > 0; i--){
        for(j = i, k = strlen(t) - 1; k > 0 && s[j] == t[k]; k--, j--)
            ;
        if(k == 0)
            return i - (strlen(t) - 1);
    }
    return -1;
}